from PyQt5.QtWidgets import *
import sys

class TextEditDemo(QWidget):
    def __init__(self,parent=None):
        super(TextEditDemo,self).__init__(parent)
        self.setWindowTitle("当行文本")

        self.resize(600,600)
        self.textEdit=QTextEdit()
        self.btnPress1=QPushButton("显示文本")
        self.btnPress2 = QPushButton("显示Html")
        layout=QVBoxLayout()
        layout.addWidget(self.textEdit)
        layout.addWidget(self.btnPress1)
        layout.addWidget(self.btnPress2)
        self.setLayout(layout)
        self.btnPress1.clicked.connect(self.btnPress1_click)
        self.btnPress2.clicked.connect(self.btnPress2_click)
    def btnPress1_click(self):
        self.textEdit.setPlainText("多行文本 \n hello python")

    def btnPress2_click(self):
        self.textEdit.setHtml("<font color='red' size='6'><red>单击按钮 <br> pyqt5 </font>")



if __name__ == '__main__':
    app=QApplication(sys.argv)
    win=TextEditDemo()
    win.show()
    sys.exit(app.exec_())